package com.shujia.scala

import scala.io.Source

object Demo16Student {
  def main(args: Array[String]): Unit = {

    /**
      * 统计班级学生的人数
      *
      */

    Source
      .fromFile("java/data/students.txt")
      .getLines()
      .toList
      .map(line =>
        line.split(",")(4)
      )
      .groupBy(clazz => clazz) //按照班级进行分组
      .map(kv => {
        val clazz = kv._1
        val count = kv._2.length

        clazz + "," + count
      })
      .foreach(println)


  }
}
